package com.quasar.hpatient.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.quasar.hpatient.R;


public class SelectWidget extends LinearLayout {

    private View container;
    public TextView message;
    private String hit;
    private String title;
    private TextView titleview;

    public TextView getMessage() {
        return message;
    }
    public SelectWidget(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    public SelectWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public void init(Context context, AttributeSet attrs, int defStyleAttr) {
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.EditWidget);
        title = a.getString(R.styleable.EditWidget_edit_title);
        hit = a.getString(R.styleable.EditWidget_edit_hit);
        a.recycle();
        LayoutInflater.from(context).inflate(R.layout.widget_select, this);
        titleview = (TextView) findViewById(R.id.title);

        message = (TextView) findViewById(R.id.message);
        if (hit != null) {
            message.setHint(hit);
        }
        //InputType
        if (title != null) {
            titleview.setText(title);
        }
        setClickable(true);
        container = findViewById(R.id.container);
    }

    @Override
    public void setOnClickListener(OnClickListener l) {
        super.setOnClickListener(l);
        container.setOnClickListener(l);
    }

    public void setText(String text) {
        if (text == null) {
            return;
        }
        message.setText(text);
    }

    public String getText() {
        return message.getText().toString();
    }
}
